package com.newland.nxsms;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.newland.nxsms.cmpp.CMPPDao;
import com.newland.nxsms.cmpp.CMPPTaskInfo;
import com.newland.nxsms.dao.ConnectionManager;
import com.newland.nxsms.utils.AES;

public class AlreadySendDataToDb extends Thread {

//	private Connection conn;
	private CMPPDao dao;
	public AlreadySendDataToDb(CMPPDao dao) {
		this.dao = dao;
	}
	@Override
	public void run() {
		int insertCount = 0;
		List<CMPPTaskInfo> insertList = new ArrayList<CMPPTaskInfo>();
		while(true) {
			try{
				Map<String, CMPPTaskInfo> map = null;
				if (NxSmsMain.nowIsInsertSqls) {
					map = NxSmsMain.insertSqlsSec.poll();
				}
				
				if (NxSmsMain.nowIsInsertSqlsSec) {
					map = NxSmsMain.insertSqls.poll();
				}
				
				if (null != map) {
					insertCount++;
					for (Entry<String, CMPPTaskInfo> entry: map.entrySet()) {
						String seqId = entry.getKey();
						CMPPTaskInfo taskInfo = entry.getValue();
						String taskState = NxSmsMain.updateSqls.get(seqId);
						if (null != taskState) {
							taskInfo.setState(0);
							NxSmsMain.updateSqls.remove(seqId);
						}
						insertList.add(taskInfo);
					}
					if (insertCount == NxSmsMain.insertUp) {
//						Connection conn = ConnectionManager.getInstance().getConnection();
						//dao.updateInsertMsgState(conn, true, insertList);
						insertList.clear();
						insertCount = 0;
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) throws Exception {
		System.out.println(AES.decrypt("DD250D981EDAC7AC5C331C089B5549EE", "HuaDongJieSuo123"));
		System.out.println(AES.encrypt("15996559730", "HuaDongJieSuo123"));
	}
}
